package com.tgpms.vforms.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.tgpms.common.Result;
import com.tgpms.exception.ExceptionExplain;
import com.tgpms.interfaces.dto.VformInterface;
import com.tgpms.vforms.service.OrganService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

@Api(value = "OrganController", tags = "D1102 机构相关接口")
@RestController
@RequestMapping(value = "/ev/vform/organ")
public class OrganController {
	
	@Resource
    private VformInterface vformInterface;
	@Autowired
	private OrganService organService;

	@ApiOperation(value = "查询机构合同树形接口", notes = "查询机构合同树形接口", httpMethod = "POST")
	@PostMapping(value = "/selOrganTreeList")
	public Result<List<Map<String, Object>>> selOrganTreeList(
    		@RequestParam(value = "dataowner", required = false) String dataowner) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {
        	list = organService.selOrganTreeList(dataowner);
        	return Result.OK(ExceptionExplain.SUCCESS_BY_INFOS.getExplain(), list);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ERROR(ExceptionExplain.ERROR_BY_INFOS.getExplain());
        }
	}
	
	@ApiOperation(value = "查询机构接口", notes = "查询机构接口", httpMethod = "POST")
	@ApiImplicitParams({
    	@ApiImplicitParam(name = "pageNo",value = "页数",required = true,defaultValue = "1"),
    	@ApiImplicitParam(name = "pageSize",value = "每页数量",required = true,defaultValue = "10"),
    	@ApiImplicitParam(name = "entityType",value = "机构类型",required = false),
    	@ApiImplicitParam(name = "entityCode",value = "机构编码",required = false),
    	@ApiImplicitParam(name = "parentCode",value = "上级机构编码",required = false),
    	@ApiImplicitParam(name = "dataowner",value = "数据拥有者",required = true)
    })
	@PostMapping(value = "/selOrganList")
	public Result<List<Map<String, Object>>> selOrganList(
			@RequestParam(value = "pageNo", required = true,defaultValue = "1") String pageNo,
    		@RequestParam(value = "pageSize", required = true,defaultValue = "10") String pageSize,
    		@RequestParam(value = "entityType", required = false) String entityType,
    		@RequestParam(value = "entityCode", required = false) String entityCode,
    		@RequestParam(value = "parentCode", required = false) String parentCode,
    		@RequestParam(value = "dataowner", required = true) String dataowner) {
        List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
        try {
        	Map<String, Object> map = new HashMap<String, Object>();
        	map.put("pageNo", pageNo);
        	map.put("pageSize", pageSize);
        	map.put("entityType", entityType);
        	map.put("entityCode", entityCode);
        	map.put("parentCode", parentCode);
        	map.put("dataowner", dataowner);
        	list = organService.selOrganList(map);
        	return Result.OK(ExceptionExplain.SUCCESS_BY_INFOS.getExplain(), list);
        } catch (Exception e) {
            e.printStackTrace();
            return Result.ERROR(ExceptionExplain.ERROR_BY_INFOS.getExplain());
        }
	}
}
